﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace eLearning.Pages.PanelUtilities
{
    public class TitleBar : Grid
    {
        private Label title = new Label()
        {
            Content = "Untitle Panel",            
            Height = 24,
            Width = Double.NaN
        };

        public string Title
        {
            get { return (string) title.Content; }
            set { title.Content = value; }
        }

        private Panel Parent;

        public TitleBar()
        {
            this.Loaded += new RoutedEventHandler(TitleBar_Loaded);
            this.Children.Add(title);
        }

        void TitleBar_Loaded(object sender, RoutedEventArgs e)
        {
            this.Height = title.Height;
            this.Width = Double.NaN;
            this.Visibility = Visibility.Collapsed;
            this.VerticalAlignment = VerticalAlignment.Top;            

            this.title.HorizontalAlignment = HorizontalAlignment.Left;

            this.Parent = ButtonEvent.FindParent<Panel>(this);
            if (this.Parent == null) return;
            this.Parent.MouseEnter += new MouseEventHandler(Parent_MouseEnter);
            this.Parent.MouseLeave += new MouseEventHandler(Parent_MouseLeave);

            //foreach (UIElement x in this.Children) if (x is ButtonEvent) ((ButtonEvent)x).ParentPanel = this.Parent;
        }

        void Parent_MouseEnter(object sender, RoutedEventArgs e)
        { 
            this.Visibility = Visibility.Visible;
        }

        void Parent_MouseLeave(object sender, RoutedEventArgs e)
        { this.Visibility = Visibility.Collapsed; }
    }
}
